<template>
	<view class="main">
		<u-navbar :is-back="false" title="订单管理" :background="background" back-icon-color="#000000" title-color="#33312D"
			title-bold="true"></u-navbar>
		<view class="tabs">
			<view :class="index==ex?'tabed':'tab'" v-for="(item,index) in tab" :key="index" @click="tabeds(index)">
				<text>{{item}}</text>
				<view class="xian" v-if="index==ex"></view>
			</view>
		</view>
		<view class="mine_take" v-if="ex==0">
			<view class="alls" v-for="(item,index) in orderlist" :key="index">
				<view class="top">
					<text>预定订单</text>
					<text class="time">付款时间:{{formatTime(item.pay_time,'YYYY-MM-DD hh:mm:ss')}}</text>
				</view>
				<view class="content" @click="router('../order_reserve/order_reserve',item)">
					<view class="id">
						订单编号:{{item.orderno}}
					</view>
					<view class="shop_details" v-for="(shop,id) in item.good_info" :key="id">
						<view class="left">
							<image :src="shop.image" mode=""></image>
							<view class="shop_tit">
								{{shop.name}}
								<text>{{shop.specs}}</text>
							</view>
						</view>
						<view class="right">
							<view>
								¥{{shop.price}}
							</view>
							<text>x{{shop.amount}}</text>
						</view>
					</view>

				</view>
				<view class="money">
					实付: ¥{{item.pay_true}}
				</view>
				<view class="button2">
					<view class="left" @click="reserve(item.id,0)">
						取消预定
					</view>
					<view class="right" @click="reserve(item.id,1)">
						确定预定
					</view>
				</view>
			</view>
		</view>
		<view class="mine_take" v-if="ex==1">
			<view class="serchtake">
				<input type="text" placeholder="请输入核销码查看订单" v-model="values"  @confirm="findcode"/>
			</view>
			<view class="alls" v-for="(item,index) in orderlist" :key="index">
				<view class="top">
					<text>自取订单</text>
					<text class="time">付款时间:{{formatTime(item.pay_time,'YYYY-MM-DD hh:mm:ss')}}</text>
				</view>
				<view class="content" @click="router('../order_details/order_details',item,takestat)">
					<view class="id">
						订单编号:{{item.orderno}}
					</view>
					<view class="shop_details" v-for="(shop,id) in item.good_info" :key="id">
						<view class="left">
							<image :src="shop.image" mode=""></image>
							<view class="shop_tit">
								{{shop.name}}
								<text>{{shop.specs}}</text>
							</view>
						</view>
						<view class="right">
							<view>
								¥{{shop.price}}
							</view>
							<text>x{{shop.amount}}</text>
						</view>
					</view>


				</view>
				<view class="money">
					实付: ¥{{item.pay_true}}
				</view>
				<view class="button" v-if="takestat" @click="takeorder(item.orderno)">
					确认取单
				</view>
			</view>
		</view>

		<view class="mine_take" v-if="ex==2">
			<view class="alls" v-for="(item,index) in orderlist" :key="index">
				<view class="top">
					<text>进行订单</text>
					<text class="time">付款时间:{{formatTime(item.pay_time,'YYYY-MM-DD hh:mm:ss')}}</text>
				</view>
				<view class="content" @click="router('../order_conduct/order_conduct',item)">
					<view class="id">
						订单编号:{{item.orderno}}
					</view>
					<view class="shop_details" v-for="(shop,id) in item.good_info" :key="id">
						<view class="left">
							<image :src="shop.image" mode=""></image>
							<view class="shop_tit">
								{{shop.name}}
								<text>{{shop.specs}}</text>
							</view>
						</view>
						<view class="right">
							<view>
								¥{{shop.price}}
							</view>
							<text>x{{shop.amount}}</text>
						</view>
					</view>
				</view>
				<view class="money">
					实付: ¥{{item.pay_true}}
				</view>
<!-- 				<view class="button">
					订单完成
				</view> -->
			</view>
		</view>
		<view class="mine_take" v-if="ex==3">
			<view class="alls" v-for="(item,index) in orderlist" :key="index">
				<view class="top">
					<text>完成订单</text>
					<text class="time">付款时间:{{formatTime(item.pay_time,'YYYY-MM-DD hh:mm:ss')}}</text>
				</view>
				<view class="content" @click="router('../order_finish/order_finish',item)">
					<view class="id">
						订单编号:{{item.orderno}}
					</view>
					<view class="shop_details" v-for="(shop,id) in item.good_info" :key="id">
						<view class="left">
							<image :src="shop.image" mode=""></image>
							<view class="shop_tit">
								{{shop.name}}
								<text>{{shop.specs}}</text>
							</view>
						</view>
						<view class="right">
							<view>
								¥{{shop.price}}
							</view>
							<text>x{{shop.amount}}</text>
						</view>
					</view>


				</view>
				<view class="money">
					实付: ¥{{item.pay_true}}
				</view>

			</view>
		</view>
		<view class="mine_take" v-if="ex==4">
			<view class="alls" v-for="(item,index) in orderlist" :key="index">
				<view class="top">
					<text>退款订单</text>
					<text class="time">付款时间:{{formatTime(item.pay_time,'YYYY-MM-DD hh:mm:ss')}}</text>
				</view>
				<view class="content" @click="router('../turn_details/turn_details',item)">
					<view class="id">
						订单编号:{{item.refund_orderno}}
					</view>
					<view class="shop_details" v-for="(shop,id) in item.good_info" :key="id">
						<view class="left">
							<image :src="shop.image" mode=""></image>
							<view class="shop_tit">
								{{shop.name}}
								<text>{{shop.specs}}</text>
							</view>
						</view>
						<view class="right">
							<view>
								¥{{shop.price}}
							</view>
							<text>x{{shop.amount}}</text>
						</view>
					</view>


				</view>
				<view class="money">
					实付: ¥{{item.order_money}}
				</view>
				<view class="button2" v-if="item.status==0">
					<view class="left" @click="off(item.rid,2)">
						退款驳回
					</view>
					<view class="right" @click="off(item.rid,3)">
						确认退款
					</view>
				</view>
				<view class="button3"v-if="item.status==2">
					退款失败
				</view>
				<view class="button3"v-if="item.status==3">
					退款完成
				</view>
			</view>
			<!-- <view class="alls">
				<view class="top">
					<text>退款订单</text>
					<text class="time">付款时间:2020-03-12</text>
				</view>
				<view class="content" @click="router('../order_details/order_details')">
					<view class="id">
						订单编号:29057219092
					</view>
					<view class="shop_details">
						<view class="left">
							<image src="../../../static/images/ewm.jpg" mode=""></image>
							<view class="shop_tit">
								玫瑰美食临安手剥山核桃、小核桃颗颗 美味可口一口停不下来，活动中更实..
								<text>原味-500g</text>
							</view>
						</view>
						<view class="right">
							<view>
								¥22.70
							</view>
							<text>x2</text>
						</view>
					</view>

				</view>
				<view class="money">
					实付: ¥55.60
				</view>
				<view class="button2">
					<view class="left">
						退款驳回
					</view>
					<view class="right">
						确认退款
					</view>
				</view>
			</view> -->
		</view>

	</view>
</template>
<script>
	export default {
		data() {
			return {
				background: {
					backgroundColor: '#fff'
				},
				tab: ['预订订单', '自取订单', '进行订单', '完成订单', '退款订单'],
				ex: 0,
				type: 0, //订单列表初始化
				orderlist: [],
				values: '',
				takestat:false,
			}
		},
		onLoad() {
			this.getorder()

		},
		mounted() {

		},
		onShow() {},
		methods: {
				reserve(id,status){
					global.$http.request({
						url:'/shopapi/order/orderStatus',
						data:{
							token:uni.getStorageSync('token'),
							id:id,
							status:status
						}
					}).then(res=>{
						if(res.data.code==200){
							uni.showToast({
								title:res.data.msg,
								icon:'none',
								duration:700
							})
							var that =this
							setTimeout(function() {
							that.getorder()
							}, 700)
						}
					})
				},
			off(id,status){
				console.log(id);
				global.$http.request({
					url:"/shopapi/order/orderStatus",
					data:{
						token:uni.getStorageSync('token'),
						id:id,
						status:status,
					}
				}).then(res=>{
					if(res.data.code==200){
						uni.showToast({
							title:res.data.msg,
							icon:'none',
							duration:700
						})	
						this.getorder()
					}
				})
			},
			takeorder(id){
				global.$http.request({
					url:'/shopapi/order/qudan',
					data:{
						orderno:id
					}
				}).then(res=>{
					if(res.data.code==200){
					uni.showToast({
						title:res.data.msg,
						icon:'none',
						duration:700	
					})
					this.values=''
					var that =this
					setTimeout(function(){
						that.getorder()
					},700)
					}
				})
			},
			//查找核销码相同的订单
			findcode(){
				if(this.values==''){
					this.getorder()
					this.takestat=false
				}else{
					global.$http.request({
						url:'/shopapi/order/cxzt',
						data:{
							token:uni.getStorageSync('token'),
							code:this.values
						}
					}).then(res=>{
						console.log(res);
						if(res==undefined){
							this.orderlist=[]
						}
						if(res.data.code==200){
								this.takestat=true
								this.orderlist=res.data.data

						}
					})
				}
			},
			//tab栏切换
			tabeds(e) {
				this.values=''
				this.takestat=false
				console.log(e);
				this.ex = e
				this.type = e
				this.getorder()
			},
			//跳转页面
			router(path, details) {
				uni.navigateTo({
					url: path + '?details=' + encodeURIComponent(JSON.stringify(details))+'&status='+this.takestat
				})
			},
			//获取订单信息
			getorder() {
				global.$http.request({
					url: '/shopapi/order/orderList',
					data: {
						token: uni.getStorageSync('token'),
						type: this.type
					}
				}).then(res => {
					if (res.data.code == 200) {
						console.log(res.data.data);
						this.orderlist = res.data.data
					}
				})
			},

		}
	}
</script>
<style lang="scss">
	page {
		font-family: Source Han Sans CN;
		width: 750rpx;
		margin: 0 auto;
		background-color: #f7f7f7;

		.main {

			width: 750rpx;
			margin: 0 auto;

			.tabs {
				width: 750rpx;
				position: fixed;
				margin-bottom: 2rpx;
				background-color: #fff;
				z-index: 999;
				display: flex;
				justify-content: space-around;
				padding: 30rpx 0 0 0;
				height: 88rpx;

				.tab {


					font-size: 26rpx;
					font-weight: 400;
					color: #000000;

				}

				.tabed {
					display: flex;
					align-items: center;
					flex-direction: column;
					font-size: 26rpx;
					font-weight: 400;
					color: #FF1900;

					.xian {
						margin-top: 20rpx;
						width: 40rpx;
						height: 4rpx;
						background: #FF1900;
					}
				}
			}

			.mine_take {
				margin-top: 88rpx;
				width: 750rpx;
				.serchtake {
					input {
						width: 730rpx;
						height: 80rpx;
						border-top: 2rpx solid #b5bfc8;
						border-bottom: 2rpx solid #b5bfc8;
						padding: 0 10rpx;
					}
				}
				.alls {
					width: 750rpx;
					padding: 24rpx 23rpx 18rpx 23rpx;
					background-color: #fff;
					margin-bottom: 4rpx;

					.top {
						display: flex;
						justify-content: space-between;
						align-items: center;
						padding-bottom: 21rpx;

						text {
							font-size: 26rpx;
							font-weight: 400;
							color: #FF0000;
						}

						.time {
							font-size: 24rpx;
							font-weight: 400;
							color: #4D4D4D;
						}
					}

					.content {
						padding: 16rpx;
						background: #F8F8F8;

						.id {
							font-size: 20rpx;
							font-weight: 400;
							color: #4D4D4D;
						}

						.shop_details {
							padding-top: 20rpx;
							display: flex;
							justify-content: space-between;

							image {
								width: 114rpx;
								height: 114rpx;
							}

							.left {
								display: flex;

								.shop_tit {
									width: 420rpx;
									padding-left: 8rpx;
									font-size: 24rpx;
									font-weight: 400;
									color: #000000;
									line-height: 30rpx;

									text {
										display: block;
										font-size: 20rpx;
										font-weight: 400;
										color: #4D4D4D;
										padding-top: 16rpx;
									}
								}

							}

							.right {
								text-align: right;

								view {
									font-size: 24rpx;
									font-weight: 400;
									color: #000000;
									line-height: 27rpx;
								}

								text {
									font-size: 20rpx;
									font-weight: 400;
									color: #4D4D4D;
								}
							}
						}
					}

					.money {
						font-size: 30rpx;
						font-weight: 400;
						color: #000000;
						padding: 30rpx 0;
						text-align: right;
					}

					.button {
						background: #E22222;
						text-align: center;
						padding: 18rpx 0;
						width: 710rpx;
						margin: 0 auto;
						border-radius: 100rpx;
						font-size: 26rpx;
						font-weight: 400;
						color: #FFFFFF;
					}

					.button3 {
						text-align: center;
						padding: 18rpx 0;
						width: 710rpx;
						margin: 0 auto;
						border-radius: 100rpx;
						font-size: 26rpx;
						font-weight: 400;
						color: #B3B3B3;
						background: #FFFFFF;
						border: 2rpx solid #B3B3B3;
					}

					.button2 {
						text-align: center;
						display: flex;
						justify-content: space-around;
						align-items: center;

						.left {
							width: 340rpx;
							background: #808080;
							padding: 19rpx 0;
							border-radius: 62rpx;
							font-size: 26rpx;
							font-weight: 400;
							color: #FFFFFF;
						}

						.right {
							width: 340rpx;
							background: #E22222;
							padding: 19rpx 0;
							border-radius: 62rpx;
							font-size: 26rpx;
							font-weight: 400;
							color: #FFFFFF;
						}
					}
				}

			}

		}
	}
</style>
